package com.longtop.framework.sys.file.supports;

import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import com.longtop.framework.util.MapUtils;
import com.longtop.framework.util.StringUtil;

public class UpLoadedFiles {
	private Map<String, Object> uploadFileMap = null;
	private BaseMultipartRequest myUpload;

	private List<UploadFile> upLoadFiles = null;

	private List<?> excelObjectList = null;

	private boolean deleteExit = false;

	public String[] getParameterValues(String arg0) {
		// TODO Auto-generated method stub
		return myUpload.getParameterValues(arg0);
	}

	public String getParameter(String name) {
		name = StringUtil.getString(name);
		if (name.equals("")) {
			return null;
		} else {
			return myUpload.getParameter(name);
		}
	}

	@SuppressWarnings("unchecked")
	public Hashtable getParameters() {
		return myUpload.getParameters();
	}

	public List<UploadFile> getUpLoadFiles() {
		return upLoadFiles;
	}

	public void setUpLoadFiles(List<UploadFile> upLoadFiles) {
		this.upLoadFiles = upLoadFiles;
	}

	@SuppressWarnings("unchecked")
	public Enumeration<String> getParameterNames() {
		return myUpload.getParameterNames();
	}

	public String[] getFilesystemName() {
		return myUpload.getFilesystemNames();
	}

	@SuppressWarnings("unchecked")
	public Map getParameterMap() {
		return myUpload.getParameterMap();
	}

	public File getFile(String name) {
		return myUpload.getFile(name);
	}

	public UploadFile getUploadFile(String name) {
		MapUtils mapUtil = new MapUtils(uploadFileMap);
		return (UploadFile) mapUtil.get(name, null);
	}

	public UploadFile[] getUploadFiles(String name) {
		MapUtils mapUtil = new MapUtils(uploadFileMap);
		Object obj = mapUtil.get(name, null);
		if (obj != null) {
			if (obj.getClass().isArray()) {
				return (UploadFile[]) obj;
			} else {
				UploadFile[] upArray = new UploadFile[1];
				upArray[0] = (UploadFile) obj;
				return upArray;
			}
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public Enumeration<String> getFileParameterNames() {
		// TODO Auto-generated method stub
		return myUpload.getFileNames();
	}

	public BaseMultipartRequest getMyUpload() {
		return myUpload;
	}

	public void setMyUpload(BaseMultipartRequest myUpload) {
		this.myUpload = myUpload;
	}

	@SuppressWarnings("unchecked")
	public <T> List<T> getExcelObjectList() {
		return (List<T>) excelObjectList;
	}

	public <T> void setExcelObjectList(List<T> excelObjectList) {
		this.excelObjectList = excelObjectList;
	}

	public Map<String, Object> getUploadFileMap() {
		return uploadFileMap;
	}

	public void setUploadFileMap(Map<String, Object> uploadFileMap) {
		this.uploadFileMap = uploadFileMap;
	}

	public boolean isDeleteExit() {
		return deleteExit;
	}

	public void setDeleteExit(boolean deleteExit) {
		this.deleteExit = deleteExit;
	}
}
